package com.windsea.relationshipmining.api;

import java.util.ArrayList;

public class StringApi {

	public static ArrayList<String> relationshipStringToArray(String relation) {
		ArrayList<String> arrRelation = new ArrayList<String>();
		if (relation != null) {
			String[] tokens = relation.split("&");
			int i = 0;
			do {
				arrRelation.add(tokens[i]);
				i++;
			} while (i < tokens.length);
		}
		return arrRelation;
	}

	public static String relationshipArrayToString(ArrayList<String> arrRelation) {
		String relation = "";
		if(!arrRelation.isEmpty()){
		if (arrRelation.size() == 1) {
			relation = arrRelation.get(0).toString();
		} else {
			int i = 0;
			do {
				relation += arrRelation.get(i).toString() + "&";
				i++;
			} while (i < arrRelation.size());
		}
		}
		return relation;
	}
}
